package com.cn.thread.disruptor.multi;

import com.cn.thread.disruptor.domain.Trade;
import com.lmax.disruptor.WorkHandler;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

public class ConsumerMulti implements WorkHandler<Trade> {

    private String consumerId;

    private static AtomicInteger count = new AtomicInteger(0);

    private Random random = new Random();

    public ConsumerMulti(String consumerId) {
        this.consumerId = consumerId;
    }
    @Override
    public void onEvent(Trade trade) throws Exception {
        Thread.sleep(1 * random.nextInt(5));
        System.err.println("当前消费者: " + this.consumerId + ", 消费信息ID: " + trade.getId());
        count.incrementAndGet();
    }

    public int getCount(){
        return count.get();
    }
}
